/* eslint-disable prettier/prettier */
import { PermissionsAndroid, Platform } from "react-native";
import { init, Geolocation } from "react-native-amap-geolocation";
import axios from "axios";
class Geo {
    async initGeo() {
        if (Platform.OS === "android") {
            await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION);
        }
        await init({
            ios: "f72f8b4530482e817185ead39bd687fd",
            android: "f72f8b4530482e817185ead39bd687fd"
        });
        return Promise.resolve();
    }
    async getCurrentPosition() {
        await init({
            ios: "f72f8b4530482e817185ead39bd687fd",
            android: "f72f8b4530482e817185ead39bd687fd"
        });
        return new Promise((resolve, reject) => {
            console.log("开始定位");
            Geolocation.getCurrentPosition(({ coords }) => {
                resolve(coords);
            }, reject);
        })
    }
    async getCityByLocation() {
        const { longitude, latitude } = await this.getCurrentPosition();
        const res = await axios.get("https://restapi.amap.com/v3/geocode/regeo", {
            params: { location: `${longitude},${latitude}`, key: "c57030aec609f85d37df682ea8d620a9", }
        });
        return Promise.resolve(res.data);
    }
}


export default new Geo();